<?php

class UserModel extends Model {
	public $table = 'admin';

	public function getUserList(){
		return $this->order("aid ASC ")->select();
	}

	public function deleteUser($uid){
		if(empty($uid)){
			$this->error = '非法操作';
		}
		if(!$this->where("aid = $uid")->delete()){
			$this->error('删除用户失败');
			return false;
		}
		return true;
	}

	public function rePassword(){
		if(empty($_SESSION['aid'])){
			$this->error = '非法操作!请自行遵守法律法规!';
			return false;
		}
		$_POST['password'] = md5($_POST['password']);
		if(!$this->where("aid = {$_SESSION['aid']} ")->update($_POST)){
			$this->error = '密码修改失败'.mysql_error();
			return false;
		}
		return true;

	}

	public function addUser(){
		if($_POST['username']==''){
			$this->error = '用户名不能为空';
			return false;
		}
		if($_POST['password']==''){
			$this->error = '密码不能为空';
			return false;
		}
		$info = $this->where("username = '{$_POST['username']}' ")->find();
		if($info){
			$this->error = '用户名存在，请重试!';
			return false;
		}else{
			return $this->insert($_POST);
		}
		
	}

}


?>